package com.cs.study.homework._0229;

import java.util.Arrays;
import java.util.Comparator;

public class Demo5 {
    public static void main(String[] args) {
        Cat c = new Cat(1, "小黄", 100);
        Cat c1 = new Cat(2, "小黑", 200);
        Cat c2 = new Cat(2, "貉", 2000);
        Cat c3 = new Cat(2, "马云的猫", 10000);
        Cat c4 = new Cat(2, "云哥", 8000);
        Cat c5 = new Cat(3, "吉祥物", 800);
        Cat c6 = new Cat(2, "阿修罗", 9000);
        Cat c7 = new Cat(2, "云堇", 300);
        Cat c8 = new Cat(2, "咪咪", 400);
        Cat c9 = new Cat(8, "养乐多", 500);
        Cat[] cats = {c, c1, c2, c3, c4, c5, c6, c7, c8, c9};
        System.out.println(Arrays.toString(cats));


    }
}
class Cat implements Comparator<Cat> {
    int age;
    String name;
    double price;

    public Cat(int age, String name, double price) {
        this.age = age;
        this.name = name;
        this.price = price;
    }

    public int getAge() {
        return age;
    }

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    @Override
    public int compare(Cat o1, Cat o2) {
            return o1.getAge()-o2.getAge();
    }
}
